#pragma once

#include <iostream>
#include <fcntl.h>

#include "log.hpp"

int SetNonBlock(int fd)
{
    //获取flag
    int flags = fcntl(fd, F_GETFL);
    if(flags == -1)
    {
        lg(Error, "F_GETFL");
        return -1;
    }

    //设置flag
    flags |= O_NONBLOCK;
    if(fcntl(fd, F_SETFL, flags) == -1)
    {
        lg(Error, "F_SETFL");
        return -1;
    }
}